package com.wuhunyu.controller;

import com.wuhunyu.commonutils.result.CommonResult;
import com.wuhunyu.entities.EduChapter;
import com.wuhunyu.entities.EduVideo;
import com.wuhunyu.service.EduChapterService;
import com.wuhunyu.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wuhunyu
 * @since 2021-01-17
 */
@RestController
@RequestMapping("/eduChapter")
//@CrossOrigin
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterService;

    @Autowired
    private EduVideoService eduVideoService;

    @GetMapping("/selectChapters/{courseId}")
    public CommonResult selectChapters(@PathVariable("courseId") String courseId) {
        return eduChapterService.selectChapters(courseId);
    }

    @PostMapping("/addChapter")
    public CommonResult addChapter(@RequestBody(required = false) EduChapter eduChapter) {
        return eduChapterService.addChapter(eduChapter);
    }

    @GetMapping("/selectChapter/{id}")
    public CommonResult selectChapterById(@PathVariable("id") String id) {
        return eduChapterService.selectChapterById(id);
    }

    @PutMapping("/updateChapter")
    public CommonResult updateChapter(@RequestBody(required = false) EduChapter eduChapter) {
        return eduChapterService.updateChapter(eduChapter);
    }

    @DeleteMapping("/deleteChapterById/{id}")
    public CommonResult deleteChapterById(@PathVariable("id") String id) {
        return eduChapterService.deleteChapterById(id);
    }

    @PostMapping("/addVideo")
    public CommonResult addVideo(@RequestBody(required = false) EduVideo eduVideo) {
        return eduVideoService.addVideo(eduVideo);
    }

    @PutMapping("/updateVideo")
    public CommonResult updateVideo(@RequestBody(required = false) EduVideo eduVideo) {
        return eduVideoService.updateVideo(eduVideo);
    }

    @DeleteMapping("/deleteVideo/{id}")
    public CommonResult deleteVideo(@PathVariable("id") String id) {
        return eduVideoService.deleteVideo(id);
    }

}

